package com.magicsoft.share.ui.article;

import android.text.Html;
import android.util.Log;
import android.webkit.WebView;
import android.widget.TextView;

import com.magicsoft.share.R;
import com.magicsoft.share.base.BaseActivity;
import com.magicsoft.share.base.BasePresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class WebViewActivity extends BaseActivity {

    @BindView(R.id.tv_content)
    TextView TvContent;
    @BindView(R.id.webview)
    WebView webView;

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_web_view;
    }

    @Override
    public void initData() {
        setTitle("文字内容");
        String content = getIntent().getStringExtra("webiview");
        TvContent.setText(Html.fromHtml(content));
        Log.e("Webview", content);
        StringBuilder sb = new StringBuilder();
        // 拼接一段HTML代码
        sb.append("<html>");
        sb.append("<head>");
        sb.append("</head>");
        sb.append("<body>");
        sb.append(content);
        sb.append("</body>");
        sb.append("</html>");

        // 使用简单的loadData方法会导致乱码，可能是Android API的Bug
        //  show.loadData(sb.toString() , "text/html" , "utf-8");

        //  加载、并显示HTML代码
        webView.loadDataWithBaseURL(null, sb.toString(), "text/html", "utf-8", null);
    }

    @Override
    public void initView() {

    }

    @Override
    public void requestData() {

    }


    @OnClick(R.id.ibtn_left)
    public void onViewClicked() {
        finish();
    }
}
